package com.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.BuyerBean;
import com.project.bean.BuyerCarBean;
import com.project.bean.UserBean;
import com.project.service.IBuyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("buyer")
public class BuyerController {
    @Autowired
    private IBuyerService buyerService;
    @RequestMapping("addOrder")
    public String  addOrder(BuyerBean buyer, HttpServletRequest req) {
       UserBean user = (UserBean)req.getSession().getAttribute("loginUser");
       buyerService.addOrder(buyer, user.getId());
       return "ok";
    }




    @RequestMapping("findByItem")
    public IPage<BuyerBean> findByItem(Integer pageNO, String supplierName, LocalDate startDate, LocalDate endDate) {

        return buyerService.findByItem(pageNO, supplierName, startDate, endDate);
    }

    @RequestMapping("findById")
    public BuyerBean findById(Integer buyId) {
       return buyerService.findById(buyId);
    }
}
